package day06.JavaCodePractice;
import java.util.Arrays;
import java.util.Random;
public class CalTotalAvgPractice {
    public static void main(String[] args) {
        double[] scores = inputScores(10);
        double Avg = calAvg(scores);
        System.out.println("平均数为: " + Avg);
    }

    public static double[] inputScores(int numPeople) {
        double[] scores = new double[numPeople];
        Random rand = new Random();
        for(int i = 0; i < scores.length; i++) {
            scores[i] = rand.nextDouble() * 100;
            System.out.println("请录入第" + (i + 1) + "位评委的评分: " + scores[i] );
        }
        return scores;
    }

    public static double calAvg(double[] inputScores) {
        double totalVal = 0.0;
        Arrays.sort(inputScores);
        double min = inputScores[0];
        double max = inputScores[inputScores.length - 1];
        for (int i = 0; i < inputScores.length; i++) {
            totalVal += inputScores[i];
        }
        totalVal = totalVal - min - max;
        double Avg = totalVal / (inputScores.length - 2);
        return Avg;
    }
}
